USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Banks-Insert]    Script Date: [[20120914064948]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064948]]
-- Description:	Insert record into table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Insert]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null  , 
	@Bank_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Banks](/*[Bank_ID], [Bank_ParentID], [Bank_Code], [Bank_NameAr], [Bank_NameEn], [Bank_Notes], [Bank_Search]*/)
	VALUES     (/*@Bank_ID, @Bank_ParentID, @Bank_Code, @Bank_NameAr, @Bank_NameEn, @Bank_Notes, @Bank_Search*/)

	/*SELECT @Bank_RowNumber = [Bank_RowNumber], @Bank_TimeStamp = [Bank_TimeStamp]
    FROM [dbo].[Banks]
    WHERE  ( [Bank_ID] =@Bank_ID )
	AND  ( [Bank_ParentID] =@Bank_ParentID )
	AND  ( [Bank_Code] =@Bank_Code )
	AND  ( [Bank_NameAr] =@Bank_NameAr )
	AND  ( [Bank_NameEn] =@Bank_NameEn )
	AND  ( [Bank_Notes] =@Bank_Notes )
	AND  ( [Bank_Search] =@Bank_Search )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Banks-update]    Script Date: [[20120914064948]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064948]]
-- Description:	Update record in table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-update]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null  , 
	@Bank_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Bank_TimeStamp]
    FROM [dbo].[Banks]
    	WHERE ([Bank_ID] = @Bank_ID)

    IF  @OldTimeStamp = @Bank_TimeStamp
    BEGIN*/
		Update [dbo].[Banks] SET 
		/*[Bank_ID] =@Bank_ID, 
		[Bank_ParentID] =@Bank_ParentID, 
		[Bank_Code] =@Bank_Code, 
		[Bank_NameAr] =@Bank_NameAr, 
		[Bank_NameEn] =@Bank_NameEn, 
		[Bank_Notes] =@Bank_Notes, 
		[Bank_Search] =@Bank_Search*/
		/*WHERE ([Bank_ID] = @Bank_ID)*/
	/*END*/

	/*SELECT @Bank_RowNumber = [Bank_RowNumber], @Bank_TimeStamp = [Bank_TimeStamp]
    FROM [dbo].[Banks]
	WHERE ([Bank_ID] = @Bank_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Banks-Insert-Update]    Script Date: [[20120914064948]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064948]]
-- Description:	Insert OR Update record into table [dbo].[Banks]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Insert-Update]
	/*@Bank_RowNumber int =Null OUTPUT , 
	@Bank_ID uniqueidentifier =Null  , 
	@Bank_ParentID uniqueidentifier =Null  , 
	@Bank_Code varchar(50) =Null  , 
	@Bank_NameAr varchar(300) =Null  , 
	@Bank_NameEn varchar(300) =Null  , 
	@Bank_Notes varchar(max) =Null  , 
	@Bank_Search varchar(max) =Null  , 
	@Bank_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Banks] 
					/*WHERE ([Bank_ID] = @Bank_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Banks](/*[Bank_ID], [Bank_ParentID], [Bank_Code], [Bank_NameAr], [Bank_NameEn], [Bank_Notes], [Bank_Search]*/)
		VALUES     (/*@Bank_ID, @Bank_ParentID, @Bank_Code, @Bank_NameAr, @Bank_NameEn, @Bank_Notes, @Bank_Search*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Bank_TimeStamp]
		FROM [dbo].[Banks]
    	WHERE ([Bank_ID] = @Bank_ID)

		IF  @OldTimeStamp = @Bank_TimeStamp
		BEGIN*/
			Update [dbo].[Banks] SET 
			/*[Bank_ID] =@Bank_ID, 
			[Bank_ParentID] =@Bank_ParentID, 
			[Bank_Code] =@Bank_Code, 
			[Bank_NameAr] =@Bank_NameAr, 
			[Bank_NameEn] =@Bank_NameEn, 
			[Bank_Notes] =@Bank_Notes, 
			[Bank_Search] =@Bank_Search*/
			/*WHERE ([Bank_ID] = @Bank_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Bank_RowNumber = [Bank_RowNumber], @Bank_TimeStamp = [Bank_TimeStamp]
    FROM [dbo].[Banks]
	WHERE ([Bank_ID] = @Bank_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Banks-Delete]    Script Date: [[20120914064948]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064948]]
-- Description:	delete records from table [dbo].[Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Delete]
	/*@Bank_RowNumber int =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@Bank_ParentID uniqueidentifier =null  , 
	@Bank_Code varchar(50) =null  , 
	@Bank_NameAr varchar(300) =null  , 
	@Bank_NameEn varchar(300) =null  , 
	@Bank_Notes varchar(max) =null  , 
	@Bank_Search varchar(max) =null  , 
	@Bank_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Banks]
	WHERE /*( [Bank_RowNumber] = ISNULL(@Bank_RowNumber, [Bank_RowNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [Bank_ParentID] = ISNULL(@Bank_ParentID, [Bank_ParentID]) )
	AND ( [Bank_Code] like ISNULL(@Bank_Code, [Bank_Code]) )
	AND ( [Bank_NameAr] like ISNULL(@Bank_NameAr, [Bank_NameAr]) )
	AND ( [Bank_NameEn] like ISNULL(@Bank_NameEn, [Bank_NameEn]) )
	AND ( [Bank_Notes] like ISNULL(@Bank_Notes, [Bank_Notes]) )
	AND ( [Bank_Search] like ISNULL(@Bank_Search, [Bank_Search]) )
	AND ( [Bank_TimeStamp] = ISNULL(@Bank_TimeStamp, [Bank_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Banks-Select]    Script Date: [[20120914064948]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064948]]
-- Description:	select records from table [dbo].[Banks] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Banks-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Banks-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Banks-Select]
	/*@Bank_RowNumber int =null  , 
	@Bank_ID uniqueidentifier =null  , 
	@Bank_ParentID uniqueidentifier =null  , 
	@Bank_Code varchar(50) =null  , 
	@Bank_NameAr varchar(300) =null  , 
	@Bank_NameEn varchar(300) =null  , 
	@Bank_Notes varchar(max) =null  , 
	@Bank_Search varchar(max) =null  , 
	@Bank_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Banks]
	WHERE /*( [Bank_RowNumber] = ISNULL(@Bank_RowNumber, [Bank_RowNumber]) )
	AND ( [Bank_ID] = ISNULL(@Bank_ID, [Bank_ID]) )
	AND ( [Bank_ParentID] = ISNULL(@Bank_ParentID, [Bank_ParentID]) )
	AND ( [Bank_Code] like ISNULL(@Bank_Code, [Bank_Code]) )
	AND ( [Bank_NameAr] like ISNULL(@Bank_NameAr, [Bank_NameAr]) )
	AND ( [Bank_NameEn] like ISNULL(@Bank_NameEn, [Bank_NameEn]) )
	AND ( [Bank_Notes] like ISNULL(@Bank_Notes, [Bank_Notes]) )
	AND ( [Bank_Search] like ISNULL(@Bank_Search, [Bank_Search]) )
	AND ( [Bank_TimeStamp] = ISNULL(@Bank_TimeStamp, [Bank_TimeStamp]) )*/
END
GO
-- =============================================
